﻿using System;
using System.Text;
using System.Xml;
using IAM.Interface.Model;
using IAM.Interface.Model.ENUM;

namespace IAM.Interface.Common.XMLResolution
{
    /// <summary>
    /// xml结点解析管理类
    /// </summary>
    public  class XMLResolutionMgnt
    {
        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="xml">xml信息包</param>
        public XMLResolutionMgnt(string xml)
        {
            _xmldocument = new XmlDocument();
            _xmldocument.LoadXml(xml);
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="xd">xml信息包</param>
        public XMLResolutionMgnt(XmlDocument xd)
        {
            _xmldocument = xd;
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="xml">xml信息包</param>
        /// <param name="transactionid">guid</param>
        public XMLResolutionMgnt(string xml, string transactionid)
        {
            _xmldocument = new XmlDocument();
            _xmldocument.LoadXml(xml);

        }
        #endregion
        #region 属性
        private XmlDocument _xmldocument;
        private ActionType _actiontype = ActionType.Nullity;
        private OperationType _operationtype = OperationType.Nullity;
        private string _transactionid = "";
        /// <summary>
        /// xml文档
        /// </summary>
        public XmlDocument XmlDocument
        {
            get
            {
                return _xmldocument;
            }
            set
            {
                _xmldocument = value;
            }
        }
        
        /// <summary>
        /// 操作类型
        /// </summary>
        public ActionType ActionType
        {
            get
            {
                return _actiontype;
            }
            set
            {
                _actiontype = value;
            }
        }
        /// <summary>
        /// 身份信息管理类型
        /// </summary>
        public OperationType OperationType
        {
            get
            {
                return _operationtype;
            }
            set
            {
                _operationtype = value;
            }
        }
        /// <summary>
        /// 发起请求的事务ID
        /// </summary>
        public string TransactionID
        {
            get
            {
                return _transactionid;
            }
            set
            {
                _transactionid = value;
            }
        }
        #endregion
        #region 创建xml结点解析对象
        /// <summary>
        /// 创建xml结点解析对象
        /// </summary>
        /// <returns></returns>
        public AbstractXMLResolution CreateXMLResolution()
        {
            AbstractXMLResolution axr = null;
            XmlElement xe = this.XmlDocument.DocumentElement;
            switch (xe.Name.ToLower())
            {
                case "requestdata"://请求包
                    axr = new Request();
                    axr.XmlDocument = this.XmlDocument;
                    break;
                case "responsedata"://响应包
                    axr = new Response(ActionType);
                    axr.XmlDocument = this.XmlDocument;
                    break;
                default:
                    axr = new Request();
                    axr.XmlDocument = this.XmlDocument;
                    break;
            }
            return axr;
        }
        #endregion
    }
}
